package cn.tansanqinger.filter;

import java.io.IOException;

import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.annotation.WebFilter;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
/**
 * 账号过滤器，如果没有登陆，将直接跳转到登陆界面
 * @author C3H2
 *
 */
@WebFilter(urlPatterns = {"/admin/*","/menu/*"})
public class AccountFilter implements Filter {

	@Override
	public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
			throws IOException, ServletException {
		HttpServletRequest request2 = (HttpServletRequest) request;
		HttpSession session = request2.getSession();
		if(session.getAttribute("admin")==null) {
			request.getRequestDispatcher("/").forward(request,response);
			return ;
		} else {
			chain.doFilter(request, response);
		}
	}

}
